package com.xiangban.yanglaodajie_platform.controller;

import com.xiangban.yanglaodajie_platform.aop.Permission;
import com.xiangban.yanglaodajie_platform.entity.ClassSign;
import com.xiangban.yanglaodajie_platform.entity.OrdersClassOrActivity;
import com.xiangban.yanglaodajie_platform.entity.Refund;
import com.xiangban.yanglaodajie_platform.entity.User;
import com.xiangban.yanglaodajie_platform.entity.dto.OrdersClassOrActivityDto;
import com.xiangban.yanglaodajie_platform.entity.dto.RefundDto;
import com.xiangban.yanglaodajie_platform.entity.dto.ScheduleInfoDto;
import com.xiangban.yanglaodajie_platform.entity.dto.UserDto;
import com.xiangban.yanglaodajie_platform.entity.res.ApiResult;
import com.xiangban.yanglaodajie_platform.entity.vo.DateVo;
import com.xiangban.yanglaodajie_platform.service.OrdersClassOrActivityService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;
import java.util.List;
import java.util.Map;

/**
 * @Author Mr. MaYaYun
 * @Data 2021/5/8 17:25
 */
@RestController
@RequestMapping("/api/v1/pri/orders_class_or_activity")
@Api(tags = "活动订单")
public class OrdersClassOrActivityController {

    @Autowired
    private OrdersClassOrActivityService ordersClassOrActivityService;


    @PostMapping("/createOrders")
    @ApiOperation("创建活动订单")
    @Permission
    public ApiResult<Object> createOrders(@RequestBody OrdersClassOrActivity ordersClassOrActivity){

        return ApiResult.newSuccess(ordersClassOrActivityService.createOrders(ordersClassOrActivity));
    }

    @PostMapping("/cancelOrders")
    @ApiOperation("取消订单")
    @Permission
    public ApiResult<Object> cancelOrders(@RequestBody OrdersClassOrActivity ordersClassOrActivity){
        ordersClassOrActivityService.cancelOrders(ordersClassOrActivity);
        return ApiResult.newSuccess();
    }

    @PostMapping("/payOrders")
    @ApiOperation("活动支付")
    @Permission
    public ApiResult<Object> payOrders(@RequestBody OrdersClassOrActivity ordersClassOrActivity){
        ordersClassOrActivityService.payOrders(ordersClassOrActivity);
        return ApiResult.newSuccess();
    }

    @PostMapping("/getClassOrActivityOrdersList")
    @ApiOperation("课程订单列表")
    @Permission
    public ApiResult<Object> classOrActivityOrdersList(@RequestBody OrdersClassOrActivity ordersClassOrActivity){
        return ApiResult.newSuccess(ordersClassOrActivityService.classOrActivityOrdersList(ordersClassOrActivity));
    }

    @PostMapping("/getClassOrActivityOrdersInfo")
    @ApiOperation("课程订单详情")
    @Permission
    public ApiResult<Object> classOrActivityOrdersInfo(@RequestBody OrdersClassOrActivity ordersClassOrActivity){
        return ApiResult.newSuccess(ordersClassOrActivityService.classOrActivityOrdersInfo(ordersClassOrActivity));
    }

    @PostMapping("/ClassOrActivityRefund")
    @ApiOperation("课程申请退款")
    @Permission
    public ApiResult<Object> ClassOrActivityRefund(@RequestBody Refund refund) {
        ordersClassOrActivityService.submitRefund(refund);
        return ApiResult.newSuccess();
    }

    @PostMapping("/ClassOrActivityRefundInfo")
    @ApiOperation("课程退款详情")
    @Permission
    public ApiResult<Object> ClassOrActivityRefundInfo(@RequestBody RefundDto refundDto) {
        return ApiResult.newSuccess(ordersClassOrActivityService.RefundInfo(refundDto));
    }

    @PostMapping("/getClassOrActivityRefundInfo")
    @ApiOperation("课程退款详情(商家)")
    @Permission(type = "shop")
    public ApiResult<Object> getClassOrActivityRefundInfo(@RequestBody RefundDto refundDto) {
        return ApiResult.newSuccess(ordersClassOrActivityService.RefundInfo(refundDto));
    }

    @PostMapping("/cancelRefund")
    @ApiOperation("取消课程退款")
    @Permission
    public ApiResult<Object> cancelRefund(@RequestBody Refund refund) {
        ordersClassOrActivityService.cancelRefund(refund);
        return ApiResult.newSuccess();
    }

    @PostMapping("/auditRefund")
    @ApiOperation("审核课程退款(商家)")
    @Permission(type = "shop")
    public ApiResult<Object> auditRefund(@RequestBody RefundDto refundDto) {
        ordersClassOrActivityService.auditRefund(refundDto);
        return ApiResult.newSuccess();
    }


    @PostMapping("/signUpOrOut")
    @ApiOperation("活动签到/签退")
    @Permission
    public ApiResult<Object> signUpOrOut(@RequestBody ClassSign classSign) throws ParseException {
        ordersClassOrActivityService.signUpOrOut(classSign);
        return ApiResult.newSuccess();
    }

    @PostMapping("/schedule")
    @ApiOperation("根据日历查课程信息")
    @Permission
    public ApiResult<Object> scheduleInfoByCalendar(@RequestBody DateVo dateVo) throws ParseException {
        return ApiResult.newSuccess(ordersClassOrActivityService.scheduleInfoByCalendar(dateVo));
    }

    @PostMapping("/getScheduleByDate")
    @ApiOperation("根据日期获取课程列表")
    @Permission
    public ApiResult<Object> getScheduleByDate(@RequestBody DateVo dateVo) throws ParseException {
        List<ScheduleInfoDto> list = ordersClassOrActivityService.getScheduleByDate(dateVo);
        return ApiResult.newSuccess(list);
    }

    @PostMapping("/getMyClass")
    @ApiOperation("我的班级")
    @Permission(roles = "teacher")
    public ApiResult<Object> myClass(@RequestBody UserDto userDto){
        return ApiResult.newSuccess(ordersClassOrActivityService.myClass(userDto));
    }


    @PostMapping("/classStudents")
    @ApiOperation("课程学生报名信息")
    @Permission(roles = "teacher")
    public ApiResult<Object> classStudents(@RequestBody OrdersClassOrActivity ordersClassOrActivity){
        return ApiResult.newSuccess(ordersClassOrActivityService.classStudents(ordersClassOrActivity));
    }


}
